package cuongnh.project.japanesediary.vocabulary.ui.wizard;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cuongnh.project.japanesediary.vocabulary.common.CommonServices;
import cuongnh.project.japanesediary.vocabulary.model.Grammar;
import cuongnh.project.japanesediary.vocabulary.ui.wizard.page.NewGrammarWizardPage;

@Component("newGrammarWizard")
@Scope("prototype")
public class AddGrammarWizard extends Wizard implements INewWizard {

	private Grammar grammar;
	private NewGrammarWizardPage page;
	private IWorkbench workbench;

	@Autowired
	private CommonServices commonServices;

	public AddGrammarWizard() {
		setWindowTitle("New Wizard");
		this.grammar = new Grammar();
	}

	public AddGrammarWizard(CommonServices commonServices,
			Grammar grammar) {
		setWindowTitle("New Wizard");
		this.grammar = grammar;
		this.commonServices = commonServices;
	}

	@Override
	public void addPages() {
		page = new NewGrammarWizardPage(grammar);
		addPage(page);
	}

	@Override
	public boolean performFinish() {
		commonServices.getGrammarDao().saveOrUpdate(grammar);
		return true;
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbench = workbench;

	}
	
	public Grammar getGrammar() {
		return grammar;
	}

}
